﻿<%@ Page Title="" Language="C#" MasterPageFile="~/site.master" AutoEventWireup="true" CodeBehind="Contact.aspx.cs" Inherits="CodeCamp12.Contact" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" runat="server">
    <script type="text/javascript">
        $(function () {
            $('#btnSend').click(function () {
                $('#emailValidateForm').validate({
                   rules: {
                       sendername: "required",
                       senderemail: {
                            required:true,
                            email:true
                       },
                       messagetext:"required"
                   },
                   messages: {
                       sendername: "Your name is required",
                       senderemail: {
                           required: "Your email address is required",
                           email: "Wrong email address format"
                       },
                       messagetext: "Message text is required"
                   }
               });

               if ($('#emailValidateForm').valid()) {
                    ajaxCall('DataService.asmx/SendEmail', false,
                        "{'name':'" + $('#txtSenderName').val() + "','from':'" + $('#txtSenderEmail').val() + "', 'subject':'" + $('#txtMessageSubject').val() + "', 'messageText':'" + $('#txtMessageText').val() + "'}",
                        function () {
                            alert("Message sent successfully!");
                            $('#txtSenderName').val("");
                            $('#txtSenderEmail').val("");
                            $('#txtMessageSubject').val("");
                            $('#txtMessageText').val("");
                        },
                        function () {
                            alert("Error happend while sending this message");
                        }
                    );
                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBody" runat="server">
    <h2>Contact</h2>
    <form method="GET" id="emailValidateForm" action="">
        <p>Please feel free to contact us if you have any questions, comments or suggestions.
        We'll try to get back with the answer as soon as possible</p>
        <br/>
        <br/>
        <label>Name:</label>
        <br/>
        <input type="text" id="txtSenderName" name="sendername" style="width: 300px;"/>
        <br/>
        <label>E-mail:</label>
        <br/>
        <input type="text" id="txtSenderEmail" name="senderemail" style="width: 300px;"/>
        <br/>
        <label>Subject:</label>
        <br/>
        <input type="text" id="txtMessageSubject" name="messagesubject" style="width: 300px;"/>
        <br/>
        <br/>
        <label>Message:</label>
        <br/>
        <textarea id="txtMessageText" name="messagetext" style="width: 400px; height: 200px;"></textarea>
        <br/>
        <button id="btnSend">Send</button>
    </form>
</asp:Content>
